<?php get_instance()->view('common/header');?>
<style>
.duosaixuan a{width:89px;}
.duosaixuan .after{width:89px;}
	.duosaixuan .after:after{width:2em;}
</style>
<body>
<div class="swiper-container saixuan duosaixuan">
    <div class="swiper-wrapper category">
        <?php foreach ($category as $k => $v):?>
            <a <?php if ($v['id'] == $categoryId):?> class="swiper-slide actived"
                <?php else:?> class="swiper-slide" <?php endif;?>
                href="javascript:;" data-id="<?php echo $v['id']?>"><?php echo $v['name']?></a>
        <?php endforeach;?>
        <div class="after"></div>
    </div>
</div>
<div class=" hengleft findboxtitle pr p10_0 m3 base" <?php if ($base['name'] == '全部'):?> style="display: none" <?php endif;?> >
    <div class="imgbox mr10"><img src="<?php echo $base['icon']?>" alt=""></div>
    <div class="model">
        <div class="hengleft vCenter mb10"><p class="mr5 lh10"><?php echo $base['name']?></p></div>
        <div class="hengleft vCenter">
            <p class="f08 cor6 mr10">帖子 <span class="szzz f09"><?php echo $base['total_find']?></span></p>
            <p class="f08 cor6">关注 <span class="szzz f09"><?php echo $base['total_collection']?></span></p>
        </div>
    </div>
    <a href="javascript:;" class="guanzbtn borderbtn follow">
        <img class="lefttitleimg mr5" src="<?php echo $this->staticUrl?>img/png/pic136.png" alt="">
        <span>关注</span>
    </a>
</div>
<div class="saixuan sort">
    <a href="javascript:;" data-id="1" <?php if ($sort == 1):?> class="change" <?php endif;?> >距离最近</a>
    <a href="javascript:;" data-id="2" <?php if ($sort == 2):?> class="change" <?php endif;?> >最新发布</a>
    <a href="javascript:;" data-id="3" <?php if ($sort == 3):?> class="change" <?php endif;?> >浏览最高</a>
    <a href="javascript:;" data-id="0" class="showDouble">
        地区<img class="jiantou" src="<?php echo $this->staticUrl?>img/png/pic9.png">
        <input type="hidden" id="county" value="<?php echo $county[2]?>">
    </a>
</div>
<?php if (!empty($list)):?>
    <div class="list">
        <?php foreach ($list as $k => $v):?>
            <a href="<?php echo getUrl('find/details?find_id='.$v['id'])?>">
                <div class="bor_bb p3">
                    <div class="lrimginfobox qfl pt75 pb5">
                        <div class="left fl">
                            <div class="imgbox"><img src="<?php echo $v['portrait']?>" alt=""></div>
                            <p class="f075"><?php echo $v['nickname']?></p>
                        </div>
                        <div class="right fl">
                            <div class="tit  pr qfl">
                                <span class="di f09 textEll fl"><?php echo $v['title']?></span>
                                <span class="pc fl mtmin"><?php echo $v['category_name']?></span>
                                <span class="f06 cor9 fr">浏览<?php echo $v['read_number']?>次</span>
                            </div>
                            <p class="cor6 f075 twohhide lh125 mt5"><?php echo $v['content']?></p>
                            <p class="f06 cor9 fr mt10 mb5">
                                <img class="heightimg di mbmin mr5" src="<?php echo $this->staticUrl?>img/png/pic36.png" alt="">
                                <?php echo $v['address']?>  <?php echo $v['addtime']?></p>
                        </div>
                    </div>
                </div>
            </a>
        <?php endforeach;?>
    </div>
    <div class="weui-loadmore" style="display: none">
        <div class="load">
            <i class="weui-loading"></i>
            <span class="weui-loadmore__tips">正在加载</span>
        </div>
        <span class="noC" style="display: none">没有更多内容了~</span>
    </div>
<?php else:?>
    <div class="statebox chuizhi jdjz" style="flex: 1;height: 63%;">
        <img class="stateimgda mb5" src="<?php echo $this->staticUrl?>img/default/2.png" alt="">
        <span class="f09 cor9 tc mb20">暂无数据</span>
    </div>
<?php endif;?>
<div class="posibtn">
    <a href="<?php echo getUrl('find/add')?>"><img src="<?php echo $this->staticUrl?>img/png/pic133.png" alt=""></a>
</div>
</body>
<script src="<?php echo $this->staticUrl?>js/jquery-weui.js"></script>
<script src="<?php echo $this->staticUrl?>js/base.js"></script>
<script type="text/javascript">
    $(function () {
        var page = 1,
            category_id,
            sort,
            county,
            list = true,
            is_collection = 1,
            userId = "<?php echo $this->userId?>";
        <?php if (empty($list)):?>
            list = false;
        <?php endif;?>
        //2级联动
        var data = JSON.parse('<?php echo $location?>');
        var _picker, defaultValue;
        <?php if (!empty($county)):?>
        defaultValue = ['<?php echo $county[0]?>','<?php echo $county[1]?>','<?php echo $county[2]?>'];
        <?php else:?>
        defaultValue = ['32','394','3330'];
        <?php endif;?>
        $('.showDouble').on('click', function () {
            var name = $(this).attr('data-type');
            _picker = $(this);

            weui.picker(data, {
                id:name,
                defaultValue:defaultValue,
                onChange: function (result) {
                },
                onConfirm: function (result) {
                    $('#county').val(result[2]);

                    blockUI.show('加载中...');
                    page = 1;
                    getList(0);
                    blockUI.hide();
                }
            });
        });

        /**
         * 点击分类
         */
        $(".category>a").on('click', function () {
            category_id = $(this).attr('data-id');
            sort = $(".sort").find('.change').attr('data-id');
            county = $("#county").val();
            page = 1;
            $(".category").find("a").removeClass('actived');
            $(this).addClass('actived');
            blockUI.show('加载中...');
            var weiz = $(".saixuan a.actived").index();
            var wid = $(".saixuan a").outerWidth();
            var actwid =  $(".saixuan a.actived").outerWidth();
            $(".saixuan .after").animate({left:weiz*actwid,width:actwid});
            getList(0);
            blockUI.hide();
        });

        /**
         * 点击排序
         */
        $(".sort>a").on('click', function () {
            var vl = $(this).attr('data-id');
            if (vl > 0){
                sort = vl;
                page = 1;
                $(".sort").find('a').removeClass('change');
                $(this).addClass('change');
                blockUI.show('加载中...');
                getList(0);
                blockUI.hide();
            }
        });

        /**
         * 上拉加载
         */
        var loading = false;  //状态标记
        $(document.body).infinite().on("infinite", function() {
            if(loading) return;
            loading = true;
            $(".weui-loadmore").show();
            $(".load").show();
            $(".noC").hide();
            page += 1;
            getList(1);

        });

        /**
         * 动态获取数据
         */
        function getList(t){
            if (!list){
                return;
            }
            $.ajax('<?php echo getUrl('find/getFindList');?>', {
                type:'post',
                data:{page:page,sort:sort,county:county,category_id:category_id,userId:userId},
                dataType:'json',
                error:function(){
                    blockUI.hide();
                    show_message({status:0, message:'请求超时'});
                },
                timeout:60000,
                success:function(e,textStatus,jqXHR){
                    blockUI.hide();
                    loading = false;
                    var html,
                        addressImg = "<?php echo $this->staticUrl?>img/png/pic36.png",
                        defaultImg = "<?php echo $this->staticUrl?>img/default/2.png",
                        baseImg = "<?php echo $this->staticUrl?>img/png/pic136.png",
                        list = e.data.list,
                        detailsUrl = "<?php echo getUrl('find/details?find_id=')?>",
                        CName;
                    if (t == 1){
                        if (!list.length){
                            $(document.body).destroyInfinite();
                            $(".load").hide();
                            $(".noC").show();
                            return;
                        }
                        $(".weui-loadmore").hide();
                    }else{
                        $(".weui-loadmore").hide();
                        if (!list.length){
                            $(".list").html('<div class="statebox chuizhi jdjz" style="flex: 1;height: 63%;">' +
                                '<img class="stateimgda mb5" src="'+defaultImg+'" alt="">' +
                                '<span class="f09 cor9 tc mb20">暂无数据</span>' +
                                '</div>');
                            return;
                        }else{
                            $(".list").html('');
                        }
                        var base = e.data.base;
                        if (base.name == '全部'){
                            $(".base").hide();
                        }else{
                            is_collection = base.is_Collection;
                            if (base.is_Collection == 1){
                                CName = '关注'
                            }else{
                                CName = '已关注'
                            }
                            $(".base").show();
                            $(".base").html('<div class="imgbox mr10"><img src="' +base.icon+'" alt=""></div>' +
                                '<div class="model">' +
                                    '<div class="hengleft vCenter mb10"><p class="mr5 lh10">'+base.name+'</p></div>' +
                                    '<div class="hengleft vCenter">' +
                                        '<p class="f08 cor6 mr10">帖子 <span class="szzz f09">'+base.total_find+'</span></p>' +
                                        '<p class="f08 cor6">关注 <span class="szzz f09">'+base.total_collection+'</span></p>' +
                                    '</div>' +
                                '</div>' +
                                '<a class="guanzbtn borderbtn follow"><img class="lefttitleimg mr5" src="'+baseImg+'" alt="">' +
                                '   <span>'+CName+'</span></a>');
                        }
                    }
                    $.each(list, function (key, obj) {
                        if(obj.nickname == null){
                            obj.nickname = '';
                        }
                        html = '<a href="'+detailsUrl+obj.id+'">'+
                            '<div class="bor_bb p3">'+
                                '<div class="lrimginfobox qfl pt75 pb5">' +
                                    '<div class="left fl">' +
                                        '<div class="imgbox"><img src="'+obj.portrait+'" alt=""></div>' +
                                        '<p class="f075">'+obj.nickname+'</p>' +
                                    '</div>' +
                                    '<div class="right fl">' +
                                        '<div class="tit  pr qfl">' +
                                            '<span class="di f09 textEll fl">'+obj.title+'</span>' +
                                            '<span class="pc fl mtmin">'+obj.category_name+'</span>' +
                                            '<span class="f06 cor9 fr">浏览'+obj.read_number+'次</span>' +
                                        '</div>' +
                                        '<p class="cor6 f075 twohhide lh125 mt5">'+obj.content+'</p>' +
                                        '<p class="f06 cor9 fr mt10 mb5">' +
                                            '<img class="heightimg di mbmin mr5" src="'+addressImg+'" alt="">' +
                                            obj.address+obj.addtime+
                                        '</p>' +
                                    '</div>' +
                                '</div>' +
                            '</div></a>';
                        $(".list").append(html);
                    });
                }
            });
        }

        /**
         * 点击关注
         */
        $(".base").delegate('.follow', 'click', function () {
            var _this = $(this),
                url;
            if (is_collection == 2){
                url = '<?php echo getUrl('user/rmCollection');?>';
            }else{
                url = '<?php echo getUrl('user/saveCollection');?>';
            }
            $.ajax(url, {
                type:'post',
                data:{relation_id:category_id,type:3},
                dataType:'json',
                error:function(){
                    show_message({status:0, message:'请求超时'});
                },
                timeout:60000,
                success:function(e,textStatus,jqXHR){
                    show_message(e);
                    if (e.status != 1){
                        return;
                    }
                    if (is_collection == 2){
                        is_collection = 1;
                        _this.find('span').html('关注');
                    }else{
                        is_collection = 2;
                        _this.find('span').html('已关注');
                    }
                }
            });
        });
    });
</script>
</html>